<template>
  <div class="photolist">
    <!-- tab -->
    <van-tabs animated>
      <van-tab
        v-for="(cate) in cates"
        :key="cate.id"
      >
        <template #title>
          <span @click="getImages(cate.id)">{{cate.title}}</span>
        </template>
        <div
          class="imgs-box"
          v-if="images.length > 0"
        >
          <img
            v-for="image in images"
            :key="image.id"
            v-lazy="image.img_url"
            alt=""
          >
        </div>
        <div v-else>
          暂无数据
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
export default {
  data() {
    return {
      cates: [],
      images: []
    }
  },
  methods: {
    async getImageCategory() {
      const res = await this.$http.getImageCategory()
      res.data.message.unshift({
        id: 0,
        title: '全部'
      })
      this.cates = res.data.message
      console.log(this.cates)
    },
    async getImages(id) {
      const res = await this.$http.getImages(id)
      this.images = res.data.message
    }
  },
  created() {
    this.getImageCategory()
    this.getImages(0)
  }
}
</script>
<style lang="scss" scoped>
.photolist {
  .imgs-box {
    img {
      width: 100%;
      height: 100%;
      display: block;
    }
  }
}
</style>
